<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="奖品等级" prop="name">
      <el-select v-model="ruleForm.prizelevel" placeholder="请选择礼品等级">
        <el-option label="一等奖" value="1"></el-option>
        <el-option label="二等奖" value="2"></el-option>
        <el-option label="三等奖" value="3"></el-option>
        <el-option label="四等奖" value="4"></el-option>
        <el-option label="五等奖" value="5"></el-option>
        <el-option label="六等奖" value="6"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="入库数量" prop="region">
      <el-input v-model="ruleForm.stocknum"  style="width: 200px" placeholder="请输入数量"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">添加</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import scratch from "../../api/scratch";

export default {
  data() {
    return {
      ruleForm: {
        prizelevel: '',
        stocknum: ''
      },
      rules: {
        name: [
          {required: true, message: '请输入活动名称', trigger: 'change'},
        ],
        region: [
          {required: true, message: '请输入数量', trigger: 'blur'}
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        scratch.addinfo(this.ruleForm).then(res => {
          console.log(res)
          if (res.data == true) {
            this.$message({
              type: 'success',
              message: '添加成功!',
            });
          } else {
            this.$message({
              type: 'defeated',
              message: '添加失败!',
            });
          }
        })
      });
    }
  }
}
</script>